import { createRouter, createWebHistory } from 'vue-router';
import {useCommonStore} from "@/stores/common";
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'index',
      meta: {
        title: "都经生活服务平台",
        icon: "House",
        openeds:[1],
        active:1,
      },
      redirect:'/system',
      component:()=>import("@/views/index.vue"),
      children: [{
        path: '/system',
        name: 'system',
        meta: {
          title: "系统管理",
          icon: "House",
          openeds:[1],
          active:1,
        },
        redirect:'/system',
        children: [{
          path: '/system',
          name: 'system',
          meta: {
            title: "用户管理",
            icon: "system",
            openeds:[1,'1-1'],
            active:'1-1',
          },
          children:[{
            path: '/system',
            name: 'system',
            meta: {
              title: "组织管理",
              icon: "House",
              openeds:[1,'1-1'],
              active:'1-1-1',
            },
            component: () => import('@/views/system/user/organization.vue'),
          },{
            path: '/character',
            name: 'character',
            meta: {
              title: "角色管理",
              icon: "House",
              openeds:[1,'1-1'],
              active:'1-1-2',
            },
            component: () => import('@/views/system/user/character.vue'),
          },{
            path: '/admin',
            name: 'admin',
            meta: {
              title: "用户管理",
              icon: "House",
              openeds:[1,'1-1'],
              active:'1-1-3',
            },
            component: () => import('@/views/system/user/admin.vue'),
          }]
        },{
          path: '/log',
          name: 'log',
          meta: {
            title: "操作日志",
            icon: "system",
            openeds:[1,'1-2'],
            active:'1-2',
          },
          component: () => import('@/views/system/log.vue'),
        },{
          path: '/advertising',
          name: 'advertising',
          meta: {
            title: "广告发布",
            icon: "system",
            openeds:[1,'1-3'],
            active:'1-3',
          },
          component: () => import('@/views/system/advertising.vue'),
        }]
      },{
        path: '/vehicle',
        name: 'vehicle',
        meta: {
          title: "车场管理",
          icon: "House",
          openeds:[2],
          active:2,
        },
        children: [{
          path: '/curbparking',
          name: 'curbparking',
          meta: {
            title: "路内",
            icon: "system",
            openeds:[2,'2-1'],
            active:"2-1",
          },
          redirect:'/curbparking',
          children:[{
            path: '/curbparking',
            name: 'curbparking',
            meta: {
              title: "车场管理",
              icon: "House",
              openeds:[2,'2-1-1'],
              active:"2-1-1",
            },
            component: () => import('@/views/vehicle/curbparking/curbparkingmanage.vue'),
          },{
            path: '/roadberth',
            name: 'roadberth',
            meta: {
              title: "道路泊位",
              icon: "House",
              openeds:[2,'2-1-2'],
              active:"2-1-2",
            },
            component: () => import('@/views/vehicle/curbparking/roadberth.vue'),
          },{
            path: '/cchargingrule',
            name: 'cchargingrule',
            meta: {
              title: "收费规则配置",
              icon: "House",
              openeds:[2,'2-1-3'],
              active:"2-1-3",
            },
            component: () => import('@/views/vehicle/curbparking/chargingrule.vue'),
          },{
            path: '/cequipment',
            name: 'cequipment',
            meta: {
              title: "设备配置",
              icon: "House",
              openeds:[2,'2-1-4'],
              active:"2-1-4",
            },
            component: () => import('@/views/vehicle/curbparking/equipment.vue'),
          },{
            path: '/cparameter',
            name: 'cparameter',
            meta: {
              title: "参数配置",
              icon: "House",
              openeds:[2,'2-1-5'],
              active:"2-1-5",
            },
            component: () => import('@/views/vehicle/curbparking/parameter.vue'),
          }]
        },{
          path: '/roadparking',
          name: 'roadparking',
          meta: {
            title: "路外",
            icon: "system",
            openeds:[2,'2-2'],
            active:"2-2",
          },
          component: () => import('@/views/vehicle/roadparking/roadparkingmanage.vue'),
          children:[{
            path: '/roadparking',
            name: 'roadparking',
            meta: {
              title: "车场管理",
              icon: "House",
              openeds:[2,'2-2-1'],
              active:"2-2-1",
            },
            component: () => import('@/views/vehicle/roadparking/roadparkingmanage.vue'),
          },{
            path: '/lane',
            name: 'lane',
            meta: {
              title: "车道管理",
              icon: "House",
              openeds:[2,'2-2-2'],
              active:"2-2-2",
            },
            component: () => import('@/views/vehicle/roadparking/lane.vue'),
          },{
            path: '/releaserule',
            name: 'releaserule',
            meta: {
              title: "放行规则",
              icon: "House",
              openeds:[2,'2-2-3'],
              active:"2-2-3",
            },
            component: () => import('@/views/vehicle/roadparking/releaserule.vue'),
          },{
            path: '/rchargingrules',
            name: 'rchargingrules',
            meta: {
              title: "收费规则",
              icon: "House",
              openeds:[2,'2-2-4'],
              active:"2-2-4",
            },
            component: () => import('@/views/vehicle/roadparking/chargingrules.vue'),
          },{
            path: '/requipment',
            name: 'requipment',
            meta: {
              title: "设备配置",
              icon: "House",
              openeds:[2,'2-2-5'],
              active:"2-2-5",
            },
            component: () => import('@/views/vehicle/roadparking/equipment.vue'),
          },{
            path: '/rparameter',
            name: 'rparameter',
            meta: {
              title: "参数配置",
              icon: "House",
              openeds:[2,'2-2-6'],
              active:"2-2-6",
            },
            component: () => import('@/views/vehicle/roadparking/parameter.vue'),
          }]
        }]
      }]
    },{
      path:'/login',
      name:'login',
      component:()=>import("@/views/login.vue")
    }
  ]
});
// 路由前置守卫
router.beforeEach((to, from, next) => {  
  let {labelList,saveLabelList,saveCurrLabel} = useCommonStore();
  if(!labelList.length){
    let labelArray:any = labelList;
    labelArray.push({name:to.name,title:to.meta.title,path:to.path,openeds:to.meta.openeds,active:to.meta.active});
    saveLabelList(labelArray);
    saveCurrLabel(to.name);
    console.log("next");
    console.log(to,"to")
  }
  next()
})  
export default router